﻿package com.bizmlib.framework.abstract.mvc
{
	/**
	 * Is actually a view.
	 * @author	Valentyn Derkach
	 */
	import flash.events.*;
	import flash.display.MovieClip;
	import com.bizmlib.framework.abstract.mvc.AbstractModel;
	
	
	public class AbstractView extends MovieClip
	{
	
		private var __model:AbstractModel;
		
		/**
		 * This property came from the as2 implementation and should not be used in as3 version.
		 */
		//private var viewMC:MovieClip;
	
	
		public function AbstractView(model:AbstractModel)
		{
			//trace("SiteView(" + arguments + ")");
			if(!model){
				throw new Error(this + " initialization failed: no reference to a SiteEngine instance was provided");
				return;
			}
			
			__model = model;
	
			init();
		}
	
	
		/**
		 * Getter of the site's model property
		 */
		public function get model():AbstractModel
		{
			return __model;
		}
		
		
		/**
		 * Is not invoked from anywhere yet. Reserved for future. At the moment is just a placeholder. Feel free to override and call it.
		 */
		public function build():void
		{
			// ...
		}
		/**
		 * Performes a cleanning routine, so that a instance gets ready to be destroyed and collected by a 
		 * garbage collector.
		 */
		public function clean():void
		{
			if(model)
			{
				unsubscribeFromModelEvents();
				__model = null;
			}
		}
		
		
		/**
		 * Does an initializatiion stuff. Feel free to override.
		 */
		protected function init():void
		{
			subscribeToModelEvents();
		}
		/**
		 * Subscribe to listen the model's events here.
		 */
		protected function subscribeToModelEvents():void
		{
			//trace(this + ".subscribeToModelEvents()");
		}
		/**
		 * Unsubscribe from listening a model events. Invoked from a clean method.
		 */
		protected function unsubscribeFromModelEvents():void
		{
			//trace(this + ".unsubscribeFromModelEvents(" + arguments + ")");
		}
	
	
		/**
		 * Returns a string describing an instance.
		 */
		override public function toString():String
		{
			return "[com.bizmlib.framework.abstract.mvc.AbstractView]";
		}
		
	}
}